package com.yidong;

import com.YDCommonUtils;
import com.yidong.entity.YiDongObj;
import org.apache.poi.xwpf.usermodel.*;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * 验收报告
 */
public class YanShou extends YDCommonUtils {

    public static String inPath = "D:\\code\\Projects\\yidong\\src\\main\\java\\com\\yidongcfg\\验收模板\\";
    public static String outPath = "D:\\code\\Projects\\yidong\\src\\main\\java\\com\\yidongcfg\\";


    //竣工验收报告
    public void junGong(){
        YanShou yanShou = new YanShou();
        YiDongObj obj = new YiDongObj();
        //前向
        String qianxiang = obj.getQxdw();
        //我方
        String wofang = obj.getWfdw();
        //后向
        String houxiang = obj.getHxdw();

        //前向 前向为前向  后向为我方
        obj.setQxdw(qianxiang);
        obj.setHxdw(wofang);
        yanShou.wordUtils(obj,inPath,outPath,"竣工验收报告.docx","前向");
        yanShou.wordUtils(obj,inPath,outPath,"开工报告.docx","前向");
        yanShou.wordUtils(obj,inPath,outPath,"初验报告.docx","前向");
        //售中需要
        yanShou.wordUtils(obj,inPath,outPath,"试运行报告（最好有甲方盖章）.docx","前向");
        yanShou.wordUtils(obj,inPath,outPath,"试运行记录（最好有甲方盖章）.docx","前向");
        yanShou.wordUtils(obj,inPath,outPath,"软硬件产品移交清单（需甲方盖章）.docx","前向");
        this.jinDu(obj,inPath,outPath,"进度报告.docx");
        //后向 前向为我方 后向为后向
        obj.setQxdw(wofang);
        obj.setHxdw(houxiang);
        yanShou.wordUtils(obj,inPath,outPath,"竣工验收报告.docx","后向");
    }

    //进度报告
    private void jinDu(YiDongObj obj,String inPath,String outPath,String fileName){

        int i = 1;

        if (obj.getJdList().length > 0){
            //需要做多份进度报告
            for (int num : obj.getJdList()){
                outPath = outPath + i;
                String jd = num + "%";
                obj.setJd(jd);
                YanShou yanShou = new YanShou();
                yanShou.wordUtils(obj,inPath,outPath,fileName,"");
                i++;
            }
        }
    }


    @Override
    public String changeText(String runText, YiDongObj obj) {
        runText = runText.replaceAll("%项目名称%",obj.getXmmc());
        runText = runText.replaceAll("%前向单位%",obj.getQxdw());
        runText = runText.replaceAll("%后向单位%",obj.getHxdw());
        runText = runText.replaceAll("%进度%",obj.getJd());
        return runText;
    }

}